<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function setCookie(name,value,day=0){
            // 过期时间不是必传
            if(day!=0){
                var expires = day * 24 * 60 * 60 * 1000;
                var date = new Date(+new Date()+expires);
                document.cookie = `${name}=${escape(value)};expires=${date.toUTCString()}`
                // escape-废弃 后用-encodeURIComponent代替
            }else{
                document.cookie = `${name}=${escape(value) }`
            }
        }
    </script>
</body>
</html>